Array.prototype.forEach2 = function (fun, thisArg) {
    if (typeof fun !== 'function') {
        throw new TypeError(`${fun} is not function`)
    }

    let len = this.length
    for (let i = 0; i < len; i++) {//确保索引对应的元素存在
        if (Object.prototype.hasOwnProperty.call(this, i)) {//这一步相当于可以过滤掉空选项这一项
            fun.call(thisArg, this[i], i, this)//后面这几项参数传递是因为forEach的参数有元素、索引、数组本身

        }
    }

}

let arr = [1, , 4, 5]

arr.forEach2((item) => console.log(item))//1，4，5
const numbers = [1, 2, 3, 4, 5];  

